package com.example.springboot_redis.service.serviceImpl;

import com.example.springboot_redis.Dao.Po.StudentPo;
import com.example.springboot_redis.service.RedisServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RedisServiceImpl implements RedisServiceI {

    private RedisTemplate<String, Object> redisTemplate;
public RedisServiceImpl(RedisTemplate<String, Object> redisTemplate) {
    this.redisTemplate = redisTemplate;
}
    @Override
    public boolean set(String key, Object value) {

        return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, value));
    }

    @Override
    public StudentPo get(String key) {
        // Implementation for getting a value from Redis
        Object value = redisTemplate.opsForValue().get(key);
        StudentPo studentPo = new StudentPo();
      if( value instanceof StudentPo) {
            studentPo = (StudentPo) value;
            return studentPo;
        }
        return null;
    }

    @Override
    public boolean delete(String key) {

        return redisTemplate.delete(key);
    }

    @Override
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);

    }

    public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    @Override
    public List<StudentPo> getAllHash() {



        return null; // Placeholder return statement
    }
}
